#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:01操作数据库.py
# author: 马国鑫
# datetime:2022/4/17 21:19
# software: PyCharm

"""
this is function  description 
"""

# import module your need

# 导入模块
import sqlite3

# 创建连接
conn = sqlite3.connect(r'D:\Python_code\python_web_study\db\demo.db')

# 获取游标对象
cur = conn.cursor()

# 执行sql创建表
sql = '''create table t_person(
        pno INTEGER PRIMARY KEY  AUTOINCREMENT,
        pname varchar(30) not null,
        age INTEGER 
    )'''

# 执行有可能失败抓去异常
try:
    # 执行sql
    cur.execute(sql)
except Exception as e:
    print(e)
    print('创建表失败')
finally:
    # 关闭游标关闭连接
    cur.close()
    conn.close()
